<template>
  <div>
    <!--工具条-->
    <el-col :span="24" class="toolbar" style="padding-bottom: 0px;
    display: flex;justify-content: space-between;">
      <el-form :inline="true" :model="dealTypeNew">
        <!-- <el-form-item>
          <el-input v-model="dealTypeNew.name" placeholder="姓名"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" handleSearchDealType>查询</el-button>
        </el-form-item> -->
        <el-form-item>
          <el-button type="primary" @click="handleAddDealType">{{$t('publicbtn.newlyadded')}}</el-button>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="handleRefresh">{{$t('publicbtn.refresh')}}</el-button>
        </el-form-item>

<!-- 禁用全部 -->
        <!-- <el-form-item>
          <el-button type="primary" @click="enableall">{{$t('publicbtn.enableall')}}</el-button>
        </el-form-item>
        
        <el-form-item>
          <el-button type="primary" @click="disableall">{{$t('publicbtn.disableall')}}</el-button>
        </el-form-item> -->

      </el-form>

      <el-form :inline="true" style="display:flex;align-item:center;">
        <el-form-item>
          <el-upload
            class="upload-demo"
            action=""
            :on-change="handleChange"
            :show-file-list="false"
            accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel"
            :auto-upload="false">
            <el-button size="primary" type="primary" >{{$t('publicbtn.impotr')}}</el-button>
        </el-upload>
          </el-form-item>
        <excelexport></excelexport>
      </el-form>

    </el-col>
    <!-- 新增界面 form-->

    <!-- 修改form||新增 -->
    <div class="dealTypeUpdatebox" v-if="dealTypeUpdate">
      <div class="dealTypeUpdate">
        <h2>{{ upAdddateFormTitle }}</h2>

        <el-form
          :model="updateForm"
          :rules="rules"
          ref="updateForm"
          label-width="100px"
          >
          <div>
          <div style="display: flex">
            <div class="updateLeft">

                <el-form-item
                label-width="140px"
                :label="$t('tradewallet.iconaddress')"
                prop="icon"
              >
                <el-input
                  v-model="updateForm.icon"
                  :placeholder="$t('tradewallet.pleaseiconaddress')"
                ></el-input>
              </el-form-item>

              <el-form-item
                label-width="140px"
                :label="$t('tradewallet.digitalcurrency')"
                prop="crypto"
              >
                <el-input
                  v-model="updateForm.crypto"
                  :placeholder="$t('tradewallet.currencyname')"
                ></el-input>
              </el-form-item>

                <el-form-item
                label-width="140px"
                :label="$t('tradewallet.nameofcurrency')"
                prop="name"
              >
                <el-input
                  v-model="updateForm.name"
                  :placeholder="$t('tradewallet.inputfullname')"
                ></el-input>
              </el-form-item>

              <el-form-item
                label-width="140px"
                :label="$t('tradewallet.canIdeposit')"
                prop="deposit"
              >
                <el-select
                  v-model="updateForm.deposit"
                  :placeholder="$t('tradewallet.candepositornot')"
                >
                  <el-option :label="$t('field.yes')" :value="1"></el-option>
                  <el-option :label="$t('field.no')" :value="0"></el-option>
                </el-select>
              </el-form-item>

              <el-form-item
                label-width="140px"
                :label="$t('tradewallet.withdrawcash')"
                prop="withdraw"
              >
                <el-select
                  v-model="updateForm.withdraw"
                  :placeholder="$t('tradewallet.towithdraw')"
                >
                  <el-option :label="$t('field.yes')" :value="1"></el-option>
                  <el-option :label="$t('field.no')" :value="0"></el-option>
                </el-select>
              </el-form-item>

              <el-form-item
                label-width="140px"
                :label="$t('tradewallet.canIviewrecords')"
                prop="record"
              >
                <el-select
                  v-model="updateForm.record"
                  :placeholder="$t('tradewallet.viewtherecord')"
                >
                  <el-option :label="$t('field.yes')" :value="1"></el-option>
                  <el-option :label="$t('field.no')" :value="0"></el-option>
                </el-select>
              </el-form-item>

              <el-form-item
                label-width="140px"
                :label="$t('tradewallet.itbemortgage')"
                prop="pledge"
              >
                <el-select
                  v-model="updateForm.pledge"
                  :placeholder="$t('tradewallet.mortgagedornot')"
                >
                  <el-option :label="$t('field.yes')" :value="1"></el-option>
                  <el-option :label="$t('field.no')"  :value="0"></el-option>
                </el-select>
              </el-form-item>

              <el-form-item
                label-width="140px"
                :label="$t('tradewallet.itbedisplayed')"
                prop="status"
              >
                <el-select
                  v-model="updateForm.status"
                  :placeholder="$t('tradewallet.canbedisplayed')"
                >
                  <el-option :label="$t('field.yes')" :value="1"></el-option>
                  <el-option :label="$t('field.no')"  :value="0"></el-option>
                </el-select>
              </el-form-item>

              <el-form-item
                label-width="140px"
                :label="$t('tradewallet.isitconvertible')"
                prop="exchange"
              >
                <el-select
                  v-model="updateForm.exchange"
                  :placeholder="$t('tradewallet.exchangedornot')">
                  <el-option :label="$t('field.yes')" :value="1"></el-option>
                  <el-option :label="$t('field.no')" :value="0"></el-option>
                </el-select>
              </el-form-item>

              <el-form-item
                label-width="140px"
                :label="$t('tradewallet.exchangetype')"
                prop="exchangeType">
                <el-select
                  v-model="updateForm.exchangeType"
                  :placeholder="$t('tradewallet.exchangetype')">
                  <el-option :label="$t('tradewallet.realnumber')" :value="1"></el-option>
                  <el-option :label="$t('tradewallet.percentage')" :value="2"></el-option>
                </el-select>
              </el-form-item>
            </div>

            <div class="updateCenter">
              
                <el-form-item
                label-width="190px"
                label="network"
                prop="network">
                <el-input
                  v-model="updateForm.network" 
                  :placeholder="$t('tradewallet.pleaseenternetwork')"
                ></el-input>
              </el-form-item>

               <el-form-item
                label-width="190px"
                :label="$t('tradewallet.inputsort')"
                prop="sort">
                <el-input
                  v-model="updateForm.sort" onkeyup="value=value.replace(/[^\d]+/g,'')"
                  :placeholder="$t('tradewallet.inputsort')"
                ></el-input>
              </el-form-item>

              <el-form-item
                label-width="190px"
                :label="$t('tradewallet.redemptiontimeout')"
                prop="timeout"
              >
                <el-input
                  v-model="updateForm.timeout" onkeyup="this.value=this.value.replace(/[^0-9]+/,'');"
                  :placeholder="$t('tradewallet.redemptiontimeout')"
                ></el-input>
              </el-form-item>

              <el-form-item
                label-width="190px"
                :label="$t('tradewallet.buy')"
                prop="exchangeUp">
                <el-input
                  v-model="updateForm.exchangeUp" onkeyup="this.value=this.value.replace(/\-/g,'')" 
                  :placeholder="$t('tradewallet.but')"
                ></el-input>
              </el-form-item>

              <el-form-item
                label-width="190px"
                :label="$t('tradewallet.side')"
                prop="exchangeDown"
              >
                <el-input
                  v-model="updateForm.exchangeDown"  onkeyup="this.value=this.value.replace(/\-/g,'')"
                  :placeholder="$t('tradewallet.sidet')"
                ></el-input>
              </el-form-item>

              <el-form-item
                label-width="190px"
                :label="$t('tradewallet.withdrawal')"
                prop="fee">
                <el-input
                  v-model="updateForm.fee" onkeyup="this.value=this.value.replace(/\-/g,'')" 
                  :placeholder="$t('tradewallet.withdrawalfee')"
                ></el-input>
              </el-form-item>

              <el-form-item
                label-width="190px"
                :label="$t('tradewallet.atleast')"
                prop="exchangeMin">
                <el-input
                  v-model="updateForm.exchangeMin"  onkeyup="this.value=this.value.replace(/\-/g,'')"
                  :placeholder="$t('tradewallet.redeemable')"
                ></el-input>
              </el-form-item>

              <el-form-item
                label-width="190px"
                :label="$t('tradewallet.exchangeatmost')"
                prop="exchangeMax"
              >
                <el-input
                  v-model="updateForm.exchangeMax"  onkeyup="this.value=this.value.replace(/\-/g,'')"
                  :placeholder="$t('tradewallet.ofredeemable')"
                ></el-input>
              </el-form-item>

              <el-form-item
                label-width="190px"
                :label="$t('tradewallet.everyday')"
                prop="exchangeDayMin">
                <el-input
                  v-model="updateForm.exchangeDayMin"  onkeyup="this.value=this.value.replace(/\-/g,'')"
                  :placeholder="$t('tradewallet.exchangedperday')"
                >
                 <template slot="append">USD</template>
                 </el-input>
              </el-form-item>

              <el-form-item
                label-width="190px"
                :label="$t('tradewallet.mosteveryday')"
                prop="exchangeDayMax">
                <el-input
                  v-model="updateForm.exchangeDayMax" onkeyup="this.value=this.value.replace(/\-/g,'')"
                  :placeholder="$t('tradewallet.exchangedeverday')"
                >
                 <template slot="append">USD</template>
                 </el-input>
              </el-form-item>

            </div>

              <div class="updateRight">
              
              <el-form-item
                label-width="190px"
                :label="$t('tradewallet.cobotreatment')"
                prop="cobo"
              >
                <el-select
                  v-model="updateForm.cobo"
                  :placeholder="$t('tradewallet.cobotreatmentitle')"
                >
                  <el-option :label="$t('field.yes')" :value="1"></el-option>
                  <el-option :label="$t('field.no')" :value="0"></el-option>
                </el-select>
              </el-form-item>


              <el-form-item
                label-width="190px"
                :label="$t('tradewallet.exchangetype')"
                prop="pcType">
                <el-select
                  v-model="updateForm.pcType"
                  :placeholder="$t('tradewallet.officialexchangetype')">
                  <el-option :label="$t('tradewallet.realnumber')" :value="1"></el-option>
                  <el-option :label="$t('tradewallet.percentage')" :value="2"></el-option>
                  <el-option :label="$t('tradewallet.notselected')" :value="0"></el-option>
                </el-select>
              </el-form-item>

                  <el-form-item
                label-width="190px"
                :label="$t('tradewallet.website')"
                prop="pcUp">
                <el-input
                  v-model="updateForm.pcUp" onkeyup="this.value=this.value.replace(/[^\-?\d.]/g,'')"
                  :placeholder="$t('tradewallet.websiteipt')"
                ></el-input>
              </el-form-item>

              <el-form-item
                label-width="190px"
               :label="$t('tradewallet.markdown')"
                prop="pcDown">
                <el-input
                  v-model="updateForm.pcDown" onkeyup="this.value=this.value.replace(/[^\-?\d.]/g,'')"
                  :placeholder="$t('tradewallet.markdownipt')"
                ></el-input>
              </el-form-item>

              <el-form-item
                label-width="190px"
               :label="$t('field.remarksmessage')"
                prop="remark">
                <el-input
                  v-model="updateForm.remark" 
                  :placeholder="$t('iptdefault.custommessage')"
                ></el-input>
              </el-form-item>
            </div>

          </div>

          <el-form-item class="exchangeRule"
                label-width="140px"
                :label="$t('tradewallet.exchangeRule')"
                prop="exchangeRule">
                <el-input
                  v-model="updateForm.exchangeRule" 
                  :placeholder="$t('tradewallet.iputexchangeRule')"
                ></el-input>
          </el-form-item>

            <el-form-item 
                class="exchangeRule"
                label-width="140px"
                :label="$t('tradewallet.exchangeBasisRule')"
                prop="exchangeBasisRule">
                <el-input
                v-model="updateForm.exchangeBasisRule" 
                :placeholder="$t('tradewallet.exchange_basis_ruleipt')"
            ></el-input>

          </el-form-item>

          </div>

          <el-form-item style="text-align: center">
            <el-button type="primary" @click="handleOnSubmit('updateForm')"
              >{{submitBtn}}</el-button
            >
            <el-button @click="resetHandForm('updateForm')">{{$t('publicbtn.cancel')}}</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>

    <!-- 交易钱包列表 -->
    <el-table   
      v-loading="loading"
      style="width: 100%"
      :data="walletList"
      id="out-table" >
      

        <el-table-column  :label="$t('tradewallet.icon')" width="120" >
        <template slot-scope="scope">
            <img  :src="scope.row.icon" alt="" style="width: 30px;height: 30px">
            <span v-show="false"> {{scope.row.icon}}</span>
          </template>
      </el-table-column> 

      <el-table-column prop="crypto" :label="$t('tradewallet.digitalcurrency')" width="180" >
      </el-table-column>

          <el-table-column prop="name" :label="$t('tradewallet.nameofcurrency')" width="180" >
      </el-table-column>  
      
          <el-table-column prop="network" label="network"  width="180" >
      </el-table-column>  

      <el-table-column :label="$t('tradewallet.itbedisplayed')" width="180">
        <template slot-scope="props">
          {{
            props.row.status == 0 ? $t('field.no') : props.row.status == 1 ? $t('field.yes') : ""
          }}
        </template>
      </el-table-column>


          <el-table-column :label="$t('tradewallet.cobotreatment')" width="180">
        <template slot-scope="props">
          {{
            props.row.cobo == 0 ? $t('field.no') : props.row.cobo == 1 ? $t('field.yes') : ""
          }}
        </template>
      </el-table-column>

      <el-table-column :label="$t('tradewallet.toexchange')" width="180">
        <template slot-scope="props">
          {{
            props.row.exchange == 0 ? $t('field.no') : props.row.exchange == 1 ? $t('field.yes') : ""
          }}
        </template>
      </el-table-column>

        <el-table-column prop="timeout" :label="$t('tradewallet.redemptiontimeout')" width="180" >
      </el-table-column>

      <el-table-column :label="$t('withdraw.withdrawals')" width="180">
        <template slot-scope="props">
          {{props.row.fee }}
        </template>
      </el-table-column>

      <el-table-column :label="$t('tradewallet.exchangsetype')" width="180">
        <template slot-scope="props">
          {{
            props.row.exchangeType == 2
              ?$t('tradewallet.percentage')
              : props.row.exchangeType == 1
              ? $t('tradewallet.realnumber')
              : ""
          }}
        </template>
      </el-table-column>

     <el-table-column
        prop="exchangeBasisRule"
        :label="$t('tradewallet.exchangeBasisRule')"
        width="180">
      </el-table-column>

      <el-table-column
        prop="exchangeRule"
        :show-overflow-tooltip = 'true'
        :label="$t('tradewallet.exchangeRule')"
        width="180"
        max-height = '60px'>
      </el-table-column>

      <el-table-column
        prop="exchangeUp"
        :label="$t('tradewallet.buysidemarkup')"
        width="180">
      </el-table-column>
     
      <el-table-column
        prop="exchangeDown"
        :label="$t('tradewallet.side')"
        width="200">
      </el-table-column>

      <el-table-column :label="$t('tradewallet.exchangetype')" width="180">
        <template slot-scope="props">
          {{ props.row.pcType ==1?$t('tradewallet.realnumber'):props.row.pcType ==2?$t('tradewallet.percentage'):$t('field.notselected') }}
        </template>
      </el-table-column>

      <el-table-column :label="$t('tradewallet.Markup')" width="180">
        <template slot-scope="props">
          {{ props.row.pcUp }}
        </template>
      </el-table-column> 
       
      <el-table-column :label="$t('tradewallet.markdown')" width="180">
        <template slot-scope="props">
          {{ props.row.pcDown }}
        </template>
      </el-table-column>

      <el-table-column :label="$t('tradewallet.atleast')" width="180">
        <template slot-scope="props">
          {{ props.row.exchangeMin }}
        </template>
      </el-table-column>

      <el-table-column :label="$t('tradewallet.exchangeatmost')"  width="180">
        <template slot-scope="props">
          {{ props.row.exchangeMax }}
        </template>
      </el-table-column>

      <el-table-column
        prop="exchangeDayMax"
      :label="$t('tradewallet.mosteveryday')"
        width="180">
        <template slot-scope="props">
          {{ props.row.exchangeDayMax }}
        </template>
      </el-table-column>

      <el-table-column
        prop="exchangeDayMin"
      :label="$t('tradewallet.everyday')"
        width="180">
        <template slot-scope="props">
          {{ props.row.exchangeDayMin }}
        </template>
      </el-table-column>

      <el-table-column :label="$t('tradewallet.depositornot')" width="180">
        <template slot-scope="props">
          {{
            props.row.deposit == 0 ? $t('field.no') : props.row.deposit == 1 ? $t('field.yes') : ""
          }}
        </template>
      </el-table-column>

      <el-table-column :label="$t('tradewallet.withdrawalornot')" width="180">
        <template slot-scope="props">
          {{
            props.row.withdraw == 0 ? $t('field.no') : props.row.withdraw == 1 ? $t('field.yes') : ""
          }}
        </template>
      </el-table-column>

      <el-table-column :label="$t('tradewallet.pledgeornot')" width="180">
        <template slot-scope="props">
          {{ props.row.pledge == 0 ? $t('field.no') : props.row.pledge == 1 ? $t('field.yes') : "" }}
        </template>
      </el-table-column>

      <el-table-column prop="sort" :label="$t('field.sort')" width="180"> </el-table-column>
     
      <el-table-column prop="createdAt" :label="$t('field.creationtime')" width="180">
      </el-table-column>

      <el-table-column prop="updateAt" :label="$t('field.upeationtime')" width="180">
      </el-table-column>

      
      <el-table-column prop="remark" :label="$t('field.remarksmessage')" width="180">
      </el-table-column>

      <el-table-column :label="$t('field.operation')" width="110" fixed="right" v-if="diction=='CS_V2'?false:true">
        <template slot-scope="props">
          <el-button size="mini" @click="handleUpDealType(props.row)">
            {{$t('field.editor')}}
          </el-button>
        </template>
      </el-table-column>

    </el-table>
  </div>
</template>

<script>
import excelexport from '@/components/export.vue'
import { getNudataRequest, postUserRequest,PatchRequest } from "@/api/api";
export default {
    components: {
            excelexport,
        },
  data() {
    return {
      submitBtn:'',
      walletList: [],
      loading: true,
      calculate: 100000000,
      upAdddateFormTitle: "",
      dealTypeUpdate: false,
      updataDealType: false, //走更新交易钱包接口
      newUpdatadealType: false, //走新增交易钱包接口
      // 修该
      updateForm: {},
      // 新增
      newUpdateForm: {
        icon:'',
        crypto: "",
        name:'',
        deposit: "",
        withdraw: "",
        record: "",
        pledge: "",
        status: "",
        exchange: "",
        exchangeType: "",
        network:'',
        sort: "",
        timeout:'',
        fee:'',
        exchangeUp: "",
        exchangeDown: "",
        exchangeMin: "",
        exchangeMax: "",
        exchangeDayMin: "",
        exchangeDayMax: "",
        pcType:'',
        pcUp:'',
        pcDown:'',
        remark:''
      },

      rules: {

          icon: [
          { required: true, message: this.$t('tradewallet.pleaseiconaddress'), trigger: "change" },
        ],
        crypto: [
          { required: true, message: this.$t('tradewallet.inputfullname'), trigger: "blur" },
          { min: 2, message:  this.$t('tradewallet.lengthis2'), trigger: "blur" },
        ],

        name: [
          { required: true, message: this.$t('tradewallet.pleaseiconaddress'), trigger: "change" },
        ],
        deposit: [
          { required: true, message:  this.$t('tradewallet.candepositornot'), trigger: "change" },
        ],
        withdraw: [
          { required: true, message: this.$t('tradewallet.towithdraw'), trigger: "change" },
        ],
        record: [
          {
            required: true,
            message: this.$t('tradewallet.viewtherecord'),
            trigger: "change",
          },
        ],

        pledge: [
          { required: true, message: this.$t('tradewallet.mortgagedornot'), trigger: "change" },
        ],

        status: [
          { required: true, message:  this.$t('tradewallet.whethertodisplay'), trigger: "change" },
        ],

        exchange: [
          { required: true, message: this.$t('tradewallet.whethertoexchange'), trigger: "change" },
        ],
       
       
        sort: [
          { required: true, message:this.$t('tradewallet.inputsort'), trigger: "change" },
        ],

        
        exchangeType: [
          { required: true, message: this.$t('tradewallet.exchangetype'), trigger: "change" },
        ],
            
        exchangeRule: [
          { required: false, message: this.$t('tradewallet.exchangetype'), trigger: "change" },
        ],

          timeout: [
          {
            required: true,
            message: this.$t('tradewallet.redemptiontimeout'),
            trigger: "blur",
          }
        ],

        exchangeUp: [
          {
            required: true,
            message:this.$t('tradewallet.buysidemarku'), 
            trigger: "blur",
          }
        ],
        exchangeDown: [
          {
            required: true,
            message:this.$t('tradewallet.sellsidemarkdown'), 
            trigger: "blur",
          }
        ],

        fee: [
          {
            required: true,
            message: this.$t('tradewallet.withdrawalfee'),
            trigger: "blur",
          }
        ],
        exchangeMin: [
          {
            required: true,
            message:  this.$t('tradewallet.redeemable'),
            trigger: "blur",
          }
        ],

        exchangeMax: [
          {
            required: true,
            message:  this.$t('tradewallet.ofredeemable'),
            trigger: "blur",
          }
        ],

        exchangeDayMin: [
          {
            required: true,
            message: this.$t('tradewallet.exchangedperday'),
            trigger: "blur",
          }
        ],

        exchangeDayMax: [
          {
            required: true,
            message: this.$t('tradewallet.exchangedeverday'),
            trigger: "blur",
          }
        ],
        

         cobo: [
          {
            required: true,
            message:  this.$t('tradewallet.cobotreatmentitle'),
            trigger: "blur",
          }
          ],

        pcType: [
          {
            required: true,
            message:  this.$t('tradewallet.officialexchangetype'),
            trigger: "blur",
          }
          ],
        pcUp: [
          {
            required: true,
            message:this.$t('tradewallet.websiteipt'),
            trigger: "blur",
          }],
        pcDown: [
          {
            required: true,
            message:  this.$t('tradewallet.markdownipt'),
            trigger: "blur",
          }],
          exchangeRule:[
             {
            required: false,
            message:  this.$t('tradewallet.iputexchangeRule'),
            trigger: "blur",
          },
           { pattern: /^[0-9|\,|\.|\||\<|\>|\=]+$/, message: '不允许输入空格等特殊符号' }
          ]
      },

      dealTypeNew: {
        name: "",
      },
      tradewalletName:[]
    };
  },
  computed: {
    // 使用对象展开运算符将 getters 混入 computed 对象中
    // ...mapGetters([
    //   'getCount'
    //   // ...
    // ])
  },
  methods: {
    // 新增交易钱包列表
    handleAddDealType() {
      this.dealTypeUpdate = true;
      this.updataDealType = false;
      this.newUpdatadealType = true;
      this.updateForm = this.newUpdateForm;
      this.submitBtn= this.$t('tradewallet.createnow')

      this.upAdddateFormTitle = this.$t('tradewallet.ewtransaction')
    },
    // 修该交易钱包
    handleUpDealType(handle) {
      this.submitBtn= this.$t('tradewallet.updatenow')
      this.upAdddateFormTitle = this.$t('tradewallet.modifytransaction')

      this.updataDealType = true;
      this.newUpdatadealType = false;
      var obj = JSON.parse(JSON.stringify(handle));
      this.dealTypeUpdate = true;
      this.updateForm = obj;
    },
    // 提交修该||提交新增
    handleOnSubmit() {
      this.$refs.updateForm.validate((valid) => {
      
        if (valid) {
     var objeUpdata = JSON.parse(JSON.stringify(this.updateForm));
          objeUpdata.fee =parseInt(objeUpdata.fee*this.calculate+0.000000001);
          objeUpdata.exchangeDayMax =parseInt(objeUpdata.exchangeDayMax*this.calculate+0.000000001);
          objeUpdata.exchangeMax =parseInt(objeUpdata.exchangeMax*this.calculate+0.000000001);
          objeUpdata.exchangeMin =parseInt(objeUpdata.exchangeMin*this.calculate+0.000000001);
          objeUpdata.exchangeDayMin =parseInt(objeUpdata.exchangeDayMin*this.calculate+0.000000001);
          if (this.updataDealType) {
            postUserRequest(objeUpdata, "/updateTradeWallet").then((res) => {
              var data = res.data;
              if (data.code == 200) {
                this.$message({
                  message: data.message,
                   type: "success",
                });
                this.getDealTypeList();
              } else {
                this.$message({
                  message: data.message,
                  type: "error",
                });
              }
              this.dealTypeUpdate = false;
            });
          } else if (this.newUpdatadealType) {
            postUserRequest(objeUpdata, "/addTradeWallet").then((res) => {
              var data = res.data;
              if (data.code == 200) {
                this.$message({
                  message: data.message,
                   type: "success",
                });
                this.getDealTypeList();
              } else {
                this.$message({
                  message: data.message,
                  type: "error",
                });
              }
              this.dealTypeUpdate = false;
            });
          }
        } else {
          return false;
        }
      });
    },
    // 关闭较交易钱包||关闭新增加以钱包
    resetHandForm() {
      this.updateForm = {};
      this.newUpdateForm = {};
      this.dealTypeUpdate = false;
      this.updataDealType = false;
      this.newUpdatadealType = false;
    },
    handleSearchDealType() {},

    // 获取交易钱包所有列表
    getDealTypeList() {
      this.loading= true

      getNudataRequest("/getTradeWalletList").then((res) => {
        var data = res.data;
        if (data.code == 200) {
          for (var i = 0; i < data.data.length; i++) {
          if(this.tradewalletName.indexOf(data.data[i].crypto)<0){
            let walletname = data.data[i].crypto
            this.tradewalletName.push(walletname)
          }
             data.data[i].fee =
              (data.data[i].fee / this.calculate).toFixed(8);
            data.data[i].exchangeDayMax =
              (data.data[i].exchangeDayMax / this.calculate).toFixed(8);
            data.data[i].exchangeMax =
              (data.data[i].exchangeMax / this.calculate).toFixed(8);
            data.data[i].exchangeMin =
              (data.data[i].exchangeMin / this.calculate).toFixed(8);
            data.data[i].exchangeDayMin =
              (data.data[i].exchangeDayMin / this.calculate).toFixed(8);
          }

          this.walletList = data.data;
        } else {
          this.$message({
            message: data.message,
            type: "error",
          });
        }
        this.loading = false;
      });
    },
    handleRefresh() {
      this.getDealTypeList();
    },
    // 啟用全部
    enableall(){
      var status = 1
      PatchRequest(status,'/updateTradeWallet').then(res=>{
          var data = res.data;
              if (data.code == 200) {
                this.$message({
                  message: data.message,
                   type: "success",
                });
                this.getDealTypeList();
              } else {
                this.$message({
                  message: data.message,
                  type: "error",
                });
              }
      })
    },
    disableall(){
      var status = 0
      PatchRequest(status,'/updateTradeWallet').then(res=>{
           var data = res.data;
              if (data.code == 200) {
                this.$message({
                  message: data.message,
                   type: "success",
                });
                this.getDealTypeList();
              } else {
                this.$message({
                  message: data.message,
                  type: "error",
                });
              }
        
      })
    },
 // excel表上传
  /** 导入按钮操作 **/
 handleChange(file, fileList) { //excel文件改变
     this.fileTemp = file.raw
      if (this.fileTemp) {
        if ((this.fileTemp.type == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') || (this.fileTemp
            .type == 'application/vnd.ms-excel')) {
          this.importExcel(this.fileTemp)
        } else {
          this.$message({
            type: 'warning',
            message:  this.$t('bulletframe.importtile')
          })
        }
      } else {
        this.$message({
          type: 'warning',
          message: this.$t('bulletframe.importuptile')
        })
      }
 },
// 科学计数法转化数组
     c(param) {
            let strParam = String(param)
            let flag = /e/.test(strParam)
            if (!flag) return param
            // 指数符号 true: 正，false: 负
            let sysbol = true
            if (/e-/.test(strParam)) {
              sysbol = false
            }
            // 指数
            let index = Number(strParam.match(/\d+$/)[0])
            // 基数
            let basis = strParam.match(/^[\d\.]+/)[0].replace(/\./, '')
            if (sysbol) {
              return basis.padEnd(index + 1, 0)
            } else {
              return basis.padStart(index + basis.length, 0).replace(/^0/, '0.')
            }
      },
    //   formatDate(numb, format) {
    //   const time = new Date((numb - 1) * 24 * 3600000 + 1)
    //   time.setYear(time.getFullYear() - 70)
    //   const year = time.getFullYear() + ''
    //   const month = time.getMonth() + 1 + ''
    //   const date = time.getDate() - 1 + ''
    //   if (format && format.length === 1) {
    //     return year + format + month + format + date
    //   }
    //   return year + (month < 10 ? '0' + month : month) + (date < 10 ? '0' + date : date)
    // },
  importExcel(obj) {
    let _this = this;
    // 通过DOM取文件数据
    this.file = obj
    var rABS = false; //是否将文件读取为二进制字符串
    var f = this.file;
    var reader = new FileReader();
    FileReader.prototype.readAsBinaryString = function(f) {
      var binary = "";
      var rABS = false; //是否将文件读取为二进制字符串
      var pt = this;
      var wb; //读取完成的数据
      var outdata;
      var reader = new FileReader();
      reader.onload = function(e) {
        var bytes = new Uint8Array(reader.result);
        var length = bytes.byteLength;
        for (var i = 0; i < length; i++) {
          binary += String.fromCharCode(bytes[i]);
        }
        var XLSX = require('xlsx');
        if (rABS) {
          wb = XLSX.read(btoa(fixdata(binary)), { //手动转化
            type: 'base64'
          });
        } else {
          wb = XLSX.read(binary, {
            type: 'binary'
          });
        }
        outdata = XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]]); //outdata就是你想要的东西
        _this.da = [...outdata]
        //这里 处理导入的excel数据
 
  let das = new Promise(function(resolve, reject){
        _this.da.map(v => {
        let crypto = v[_this.$t('tradewallet.digitalcurrency')]
        if(_this.tradewalletName.indexOf(crypto)>=0){
          _this.walletList.map(c => {
            if(c.crypto == crypto){

            let p = new Promise(function(resolve, reject){
	            let newwalletdata = {
                  id :c.id,
                  icon:v[_this.$t('tradewallet.icon')],
                  crypto:v[_this.$t('tradewallet.digitalcurrency')],
                  name:v[_this.$t('tradewallet.nameofcurrency')],
                  network:v['network'],
                  cobo:v[_this.$t('tradewallet.cobotreatment')] == _this.$t('field.yes')?1:0,
                  status:v[_this.$t('tradewallet.itbedisplayed')] ==_this.$t('field.yes')?1:0,
                  exchange:v[_this.$t('tradewallet.toexchange')] ==_this.$t('field.yes')?1:0,
                  timeout:v[_this.$t('tradewallet.redemptiontimeout')],
                  fee:parseInt(_this.c(v[_this.$t('withdraw.withdrawals')])*_this.calculate+0.000000001),
                  exchangeType:v[_this.$t('tradewallet.exchangsetype')]==_this.$t('tradewallet.percentage')?2:v[_this.$t('tradewallet.exchangsetype')] == _this.$t('tradewallet.realnumber')?1:'',
                  exchangeRule:v[_this.$t('tradewallet.exchangeRule')],
                  exchangeUp:v[_this.$t('tradewallet.buysidemarkup')],
                  exchangeDown:v[_this.$t('tradewallet.side')],
                  pcType:v[_this.$t('tradewallet.exchangetype')] ==1?_this.$t('tradewallet.realnumber'):2,
                  pcUp:v[_this.$t('tradewallet.Markup')],
                  pcDown:v[_this.$t('tradewallet.markdown')],
                  exchangeMin:parseInt(_this.c(v[_this.$t('tradewallet.atleast')])*_this.calculate+0.000000001),
                  exchangeMax:parseInt(_this.c(v[_this.$t('tradewallet.exchangeatmost')])*_this.calculate+0.000000001),
                  exchangeDayMax:parseInt(_this.c(v[_this.$t('tradewallet.mosteveryday')])*_this.calculate+0.000000001),
                  exchangeDayMin:parseInt(_this.c(v[_this.$t('tradewallet.everyday')])*_this.calculate+0.000000001),
                  deposit:v[_this.$t('tradewallet.depositornot')] ==_this.$t('field.no')?0:1,
                  withdraw:v[_this.$t('tradewallet.withdrawalornot')] ==_this.$t('field.no')?0:1,
                  pledge:v[_this.$t('tradewallet.pledgeornot')]==_this.$t('field.no')?0:1,
                  sort:v[_this.$t('field.sort')],
                  remark:v[_this.$t('field.remarksmessage')],
                  exchangeBasisRule:v[_this.$t('tradewallet.exchangeBasisRule')],
                  
            }
            resolve(newwalletdata)
                });

            p.then(res=>{
              // return
              postUserRequest(res, "/updateTradeWallet").then((res) => {
                          var data = res.data;
                          if (data.code == 200) {
                              _this.$message({
                              message: data.message,
                              type: "success",
                            });
                          } else {
                            _this.$message({
                              message: data.message,
                              type: "error",
                            });
                          }
                          _this.dealTypeUpdate = false;
                        });
            })
              
              }
              return
             })
            }
           return
          })
         resolve()
           })
           das.then(res=>{
             
          _this.getDealTypeList();
           })
      }
      
        
      reader.readAsArrayBuffer(f);
    }

    if (rABS) {
      reader.readAsArrayBuffer(f);
    } else {
      reader.readAsBinaryString(f);
    }
 },

  },

  created() {
    this.getDealTypeList();
  },
};
</script>
<style  scoped>
.dealTypeUpdate {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 99;
  padding: 20px;
  background: #fff;
  box-shadow: 0px 0px 3px #888;
}
.dealTypeUpdate h2 {
  text-align: center;
  font-size: 18px;
}
.dealTypeUpdatebox {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.2);
  z-index: 99;
}
.dealTypeUpdate .el-input{
      width: 220px;
}
.dealTypeUpdate .exchangeRule{
  width: 100%;
}
.dealTypeUpdate .exchangeRule .el-input{
  width: 100%;
}

</style>

